﻿// FlmPlane
// Object representing a vector in 2D/3D space
// 
// FLMScan - Featured by FabLab Munich

using System;
using log4net;

namespace FLMScan.Geometry
{
    class FlmVector
    {
        private ILog logger;

        private double x;
        private double y;
        private double z;

        public FlmVector(double x, double y, double z)
        {
            logger = LogManager.GetLogger(typeof(FlmVector));

            this.x = x;
            this.y = y;
            this.z = z;
        }

        public FlmVector(FlmPoint start, FlmPoint end)
        {
            logger = LogManager.GetLogger(typeof(FlmVector));

            x = end.X - start.X;
            y = end.Y - start.Y;
            z = end.Z - start.Z;            
        }

        public FlmVector CrossProduct(FlmVector vector)
        {
            double xDirection = Y * vector.Z - vector.Y * Z;
            double yDirection = vector.X * Z - X * vector.Z;
            double zDirection = X * vector.Y - Y * vector.X;

            return new FlmVector(xDirection, yDirection, zDirection);                            
        }

        public double X
        {
            get { return x; }
            set { x = value; }
        }

        public double Y
        {
            get { return y; }
            set { y = value; }
        }

        public double Z
        {
            get { return z; }
            set { z = value; }
        }

        public void Log(String prefix)
        {
            logger.DebugFormat("{0} FlmVector: x:{1} y:{2} z:{3}", prefix, X, Y, Z);
        }
    }
}
